﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BookingSite.Models;
using System.Xml.Linq;

namespace BookingSite.Controllers
{
    public class EventController : Controller
    {
        //
        // GET: /Event/

        public ActionResult Index()
        {
            ViewData["listEvent"] = BookingSite.Models.Event.LoadAll();
            return View();
        }

        public ActionResult Add()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Add(Event someEvent, string ruCaption, string enCaption, string uaCaption)
        {
            someEvent.caption = new XDocument(new XDeclaration("1.1", "UTF-8", "yes"),
                                        new XElement("table"));

            if (uaCaption != null)
            {
                someEvent.caption.Element("table").Add(
                    new XElement("event",
                        new XElement("language", language.ua),
                        new XElement("caption", uaCaption)
                    )
                );
            }

            if (ruCaption != null)
            {
                someEvent.caption.Element("table").Add(
                    new XElement("event",
                        new XElement("language", language.ru),
                        new XElement("caption", ruCaption)
                    )
                );
            }

            if (enCaption != null)
            {
                someEvent.caption.Element("table").Add(
                    new XElement("event",
                        new XElement("language", language.en),
                        new XElement("caption", enCaption)
                    )
                );
            }

            someEvent.create();

            return RedirectToAction("Index", "Event");
        }
    }
}
